/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import com.sun.lwuit.Command;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BoxLayout;
import core.ScreenEngine;
import view.additional.CellItem;
import view.additional.MenuList;
import view.commands.BackCommand;

/**
 *
 * @author Kvest
 */
public class CenterButtonSettingsMenuForm extends BasicForm implements MenuList.MenuListSelection
{
    private static final int OK_COMMAND_ID = 1;
    
    private static final int FROM_DISP_ITEM_ID = 0;
    private static final int FROM_EFIR_ITEM_ID = 1;
    
    private MenuList items;
    
    private FromDispTimeSelectForm fromDispTimeSelectForm;
    private FromEfirTimeSelectForm fromEfirTimeSelectForm;
    
    public CenterButtonSettingsMenuForm()
    {
        super("center_butt_set");
        
        init();
    }
    
    private void init()
    {
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        setScrollable(false);
        
        items = new MenuList();
        items.addItem(new CellItem(FROM_DISP_ITEM_ID ,"from_disp"));
        items.addItem(new CellItem(FROM_EFIR_ITEM_ID ,"from_efir"));
        items.setSelectionListener(this);
        addComponent(items);
        
        //Команды
        addCommand(new BackCommand());
        
        Command ok = new Command("ok", OK_COMMAND_ID)
        {
            public void actionPerformed(ActionEvent evt)
            {
                itemSelected(items.getSelectedId());
                
                evt.consume();
            }
        };
        addCommand(ok);
    }
    
    public void itemSelected(int id)
    {
        switch(id)
        {
            case FROM_DISP_ITEM_ID : showFromDispTimeSelectForm(); break;
            case FROM_EFIR_ITEM_ID : showFromEfirTimeSelectForm(); break;
        }
    }
    
    private void showFromDispTimeSelectForm()
    {
        if (fromDispTimeSelectForm == null)
        {
            fromDispTimeSelectForm = new FromDispTimeSelectForm();
        }
        
        ScreenEngine.getEngine().push(fromDispTimeSelectForm);
    }
    
    private void showFromEfirTimeSelectForm()
    {
        if (fromEfirTimeSelectForm == null)
        {
            fromEfirTimeSelectForm = new FromEfirTimeSelectForm();
        }
        
        ScreenEngine.getEngine().push(fromEfirTimeSelectForm);
    }
}
